--
-- Author: ping.wang
-- Date: 2018-07-19 21:01:26
--
local EquipGrid = class("EquipGrid")

function EquipGrid:ctor()
    self._location = 1
    self._strengthLevel = 1 --强化等级
    self._equipUUId = "" --装备唯一ID 无装备为空
    self._fashionID = 0 --时装ID

    self._equip = nil
end

function EquipGrid:read(value)
    self._location = value.location --必须有位置
    self._strengthLevel = value.level --强化等级
    self._equipUUId = value.UUID --装备唯一ID 无装备为空string
    self._fashionID = value.fationID --时装ID 无幻化也为0
    self._probability = value.probability --强化概率（万分比）
    self._hidden = value.hidden --是否隐藏
end

function EquipGrid:write(t)
    t.location = self._location
    t.level = self._strengthLevel
    t.UUID = self._equipUUId
    t.fationID = self._fashionID
    t.probability = self._probability
    t.hidden = self._hidden
end

function EquipGrid:getLocation()
    return self._location
end

function EquipGrid:getStrengthLevel()
    return self._strengthLevel
end

function EquipGrid:updateValue(value)
    -- 是否有时装的变化
    local hasAvatarChange = false
    if self._fashionID ~= value.fationID or 
        (self._fashionID == 0 and self._equipUUId ~= value.UUID) then
        hasAvatarChange = true
    end

    --是否是显示隐藏的变化
    local hasHiddenChange = false
    if self._hidden ~= value.hidden then
        hasHiddenChange = value
    end
    self._strengthLevel = value.level
    self._equipUUId = value.UUID
    self._fashionID = value.fationID
    self._probability = value.probability --强化概率
    self._hidden = value.hidden

    return hasAvatarChange, hasHiddenChange
end

function EquipGrid:getEquipUid()
    return self._equipUUId
end

function EquipGrid:getEquip(equip)
    return self._equip
end

function EquipGrid:setEquip(equip)
    self._equip = equip
end

function EquipGrid:getFashionId()
    return self._fashionID
end

function EquipGrid:getUpgradeProbability()
    return self._probability
end

--返回格子的外显id，优先使用fashionID，没有使用装备的id
function EquipGrid:getAvatarFashionId()
    if self._fashionID > 0 then
        return self._fashionID
    elseif self._equip then
        return self._equip:getId()
    end
    return 0
end

function EquipGrid:getHidden()
    return self._hidden
end

function EquipGrid:isHiddenAvatar()
    return self.location == Enums.EquipType.head and self._hidden
end

return EquipGrid